﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Crank.Core
{
    public class CommentStrippingLineProvider : ILineProvider
    {
        private ILineProvider source;

        public CommentStrippingLineProvider(ILineProvider source)
        {
            this.source = source;
        }

        private string StripComments(string source_line)
        {
            return Regex.Replace(source_line, @"#.*$", String.Empty, RegexOptions.IgnoreCase);
        }

        #region ILineProvider Members

        public bool HasLines
        {
            get { return source.HasLines; }
        }

        public string GetNextLine()
        {
            if( source.HasLines )
                return StripComments(source.GetNextLine());
            return null;
        }

        #endregion
    }
}
